package com.cheng.example.atguigu.view2;

public class ThreadTest extends Thread{

    private volatile int count = 0;
    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public void run() {
        for (;;) {
            System.out.println("子线程:"+count);
            count++;
            try {
                sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        ThreadTest tt = new ThreadTest();
        tt.start();
        for (;; ) {
//            System.out.println("main:"+tt.getCount());
//            System.out.print("");
            if (tt.getCount() >= 10) {
                tt.setCount(20);
                System.out.println("");
            }
        }



    }


}
